//
//  ZXBtnImageView.swift
//  loveBee
//
//  Created by zhangxing on 2017/8/14.
//  Copyright © 2017年 zhangXing. All rights reserved.
//

import UIKit

class ZXBtnImageView: UIView {

    var activityModelList: [ZXActivityModel]? {
        
        didSet {
            
            for (i, activityModel) in (activityModelList?.enumerated())! {
                
                btnImageList[i].sd_setBackgroundImage(with: URL.init(string: activityModel.img!), for: .normal, placeholderImage: #imageLiteral(resourceName: "guide_40_2"))
            }
            
            
        }
        
    }
    
    var btnImageList = [UIButton]()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    
    private func setupUI() {
        
        //计算按钮广告
        let btnDistance: CGFloat = 10
        
        let btnW: CGFloat = KWidth - 2 * btnDistance
        
        let btnH: CGFloat = 150

        //循环创建数组
        for i in 0..<4 {
            
            //创建
            let btn = UIButton.init(type: .custom)
            
            btn.setBackgroundImage(#imageLiteral(resourceName: "guide_40_2"), for: .normal)
            
            btn.tag = i
            
            //添加
            addSubview(btn)
            
            //设置frame
            btn.frame = CGRect(x: btnDistance, y: btnDistance * (CGFloat(i) + 1) + btnH * CGFloat(i), width: btnW, height: btnH)
            
            btn.adjustsImageWhenHighlighted = false
            
            //添加点击事件
            btn.addTarget(self, action: #selector(clickBtnImage(btn:)), for: .touchUpInside)
            
            btnImageList.append(btn)
        }
        
        
        
        
        
        
    }
    
    @objc private func clickBtnImage(btn: UIButton) {
        
        print(btn.tag)
    }
}
